﻿using System;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using EIIS.Infrastructure.Service.Business;
using EIIS.Infrastructure.Service.System;
using EIIS.Infrastructure.Model.Business;
using EIIS.Infrastructure.Model.System;
using EIIS.Presentation.Controllers.CommonSupport;
using EIIS.Presentation.Controllers.ViewModel;
using EIIS.Common;
using EIIS.Common.Jsons;
using EIIS.Common.Office;
using EIIS.FrameWork.Attributes;
using System.Web.Script;
using System.Data;
using System.Web;

namespace EIIS.Presentation.Controllers.Business
{
    /// <summary>
    /// 数据查询
    /// </summary>
    [Description("数据查询管理")]
    public class QueryController : BaseController
    {
        public IDictionaryManager DictionaryManager { get; set; }
        public IPackageManager PackageManager { get; set; }

        string[] ReportColors = new string[] { "#4572A7", "#AA4643", "#89A54E", "#80699B", "#3D96AE", "#DB843D", "#92A8CD", "#A47D7C", "#B5CA92" };

        private static IList<V_Package> exportList1;
        private static IList<V_Package> exportList5;
        private static IList<V_Package> exportList6;

        [Description("系统查询页面")]
        [ViewPage]
        public ActionResult Index1()
        {
            return View();
        }

        [Description("操作流程查询页面")]
        [ViewPage]
        public ActionResult Index2()
        {
            return View();
        }

        [Description("条码查询页面")]
        [ViewPage]
        public ActionResult Index3()
        {
            return View();
        }

        [Description("过期预警统计页面")]
        [ViewPage]
        public ActionResult Index4()
        {
            return View();
        }

        [Description("系统查询的导出")]
        public void ExportData1()
        {
            if (exportList1 != null)
            {
                DataTable dt = NPOIHelper.ToDataTable<V_Package>(exportList1,
                    "TiaoMH", "BaoMC", "LingYKS", "LingYR", "ShiYR", "FaFSJ", "FaFR", "ShiXSJ", "BaoZR", "BaoZSJ", "MieJR", "MieJSJ", "HuiSR", "HuiSSJ","ZhuangTMC");
                if (dt == null || dt.Rows.Count == 0)
                {
                    return;
                }
                //安排导出在Excel中的列的顺序
                dt.Columns["TiaoMH"].SetOrdinal(0);
                dt.Columns["BaoMC"].SetOrdinal(1);
                dt.Columns["LingYKS"].SetOrdinal(2);
                dt.Columns["LingYR"].SetOrdinal(3);
                dt.Columns["ShiYR"].SetOrdinal(4);
                dt.Columns["FaFSJ"].SetOrdinal(5);
                dt.Columns["FaFR"].SetOrdinal(6);
                dt.Columns["ShiXSJ"].SetOrdinal(7);
                dt.Columns["BaoZR"].SetOrdinal(8);
                dt.Columns["BaoZSJ"].SetOrdinal(9);
                dt.Columns["MieJR"].SetOrdinal(10);
                dt.Columns["MieJSJ"].SetOrdinal(11);
                dt.Columns["HuiSR"].SetOrdinal(12);
                dt.Columns["HuiSSJ"].SetOrdinal(13);
                dt.Columns["ZhuangTMC"].SetOrdinal(14);

                int dtCount = dt.Rows.Count;
                if (dtCount != 0)
                {
                    string strFileName = "系统查询" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls";
                    string headerText = "器械包信息一览表";
                    string[] columnNames = new string[] { "条码号", "器械包名称", "领用科室", "领用人", "使用人", "发放时间", "发放人", "失效日期", "包装人", "包装时间", "灭菌人", "灭菌时间", "回收人/清洗人", "回收时间", "当前流程" };
                    // 设置编码和附件格式
                    HttpContext.Response.ContentType = "application/vnd.ms-excel";
                    HttpContext.Response.ContentEncoding = Encoding.UTF8;
                    HttpContext.Response.Charset = "";
                    HttpContext.Response.AppendHeader("Content-Disposition",
                    "attachment;filename=" + HttpUtility.UrlEncode(strFileName, Encoding.UTF8));
                    HttpContext.Response.BinaryWrite(NPOIHelper.Export(dt, headerText, columnNames).GetBuffer());
                }   
            }
                     
            return;
        }

        [Description("过期包的导出")]
        public void ExportData5(string id)
        {
            if (exportList5 != null)
            {
                DataTable dt;
                if (id == "1")//库存过期包
                {
                    dt = NPOIHelper.ToDataTable<V_Package>(exportList5,
                       "TiaoMH", "BaoMC", "YouXQ"
                       , "BaoZR", "MieJR", "MieJRQ", "MieJGH", "MieJGC", "ShiXSJ");
                }
                else
                {
                    dt = NPOIHelper.ToDataTable<V_Package>(exportList5,
                       "TiaoMH", "BaoMC", "YouXQ"
                       , "BaoZR", "MieJR", "MieJRQ", "MieJGH", "MieJGC", "LingYKS", "LingYR", "ShiYR", "FaFRQ", "ShiXSJ");
                }
                if (dt == null || dt.Rows.Count == 0)
                {
                    return;
                }
                //安排导出在Excel中的列的顺序
                dt.Columns["TiaoMH"].SetOrdinal(0);
                dt.Columns["BaoMC"].SetOrdinal(1);
                dt.Columns["YouXQ"].SetOrdinal(2);
                dt.Columns["BaoZR"].SetOrdinal(3);
                dt.Columns["MieJR"].SetOrdinal(4);
                dt.Columns["MieJRQ"].SetOrdinal(5);
                dt.Columns["MieJGH"].SetOrdinal(6);
                dt.Columns["MieJGC"].SetOrdinal(7);
                if (id == "1")
                {
                    dt.Columns["ShiXSJ"].SetOrdinal(8);
                }
                else
                {
                    dt.Columns["LingYKS"].SetOrdinal(8);
                    dt.Columns["LingYR"].SetOrdinal(9);
                    dt.Columns["ShiYR"].SetOrdinal(10);
                    dt.Columns["FaFRQ"].SetOrdinal(11);
                    dt.Columns["ShiXSJ"].SetOrdinal(12);
                }

                int dtCount = dt.Rows.Count;
                if (dtCount != 0)
                {
                    string strHead = "库存过期包列表";
                    if (id != "1") strHead = "未归还过期包列表";
                    string strFileName = strHead + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls";
                    string headerText = strHead + "一览表";
                    string[] columnNames = new string[] { "条码号", "器械包名称", "有效期", "包装人", "灭菌人", "灭菌日期", "灭菌锅号", "灭菌锅次", "失效日期"};
                    if (id != "1")
                    {
                        columnNames = new string[] { "条码号", "器械包名称", "有效期", "包装人", "灭菌人", "灭菌日期", "灭菌锅号", "灭菌锅次", "领用科室", "领用人", "使用人", "发放日期", "失效日期" };
                    }
                    // 设置编码和附件格式
                    HttpContext.Response.ContentType = "application/vnd.ms-excel";
                    HttpContext.Response.ContentEncoding = Encoding.UTF8;
                    HttpContext.Response.Charset = "";
                    HttpContext.Response.AppendHeader("Content-Disposition",
                    "attachment;filename=" + HttpUtility.UrlEncode(strFileName, Encoding.UTF8));
                    HttpContext.Response.BinaryWrite(NPOIHelper.Export(dt, headerText, columnNames).GetBuffer());
                }
            }

            return;
        }

        [Description("预警包的导出")]
        public void ExportData6(string id)
        {
            if (exportList6 != null)
            {
                DataTable dt;
                if (id == "1" || id == "3")//库存预警包
                {
                    dt = NPOIHelper.ToDataTable<V_Package>(exportList6,
                       "TiaoMH", "BaoMC", "YouXQ"
                       , "BaoZR", "MieJR", "MieJRQ", "MieJGH", "MieJGC", "ShiXSJ");
                }
                else
                {
                    dt = NPOIHelper.ToDataTable<V_Package>(exportList6,
                       "TiaoMH", "BaoMC", "YouXQ"
                       , "BaoZR", "MieJR", "MieJRQ", "MieJGH", "MieJGC", "LingYKS", "LingYR", "ShiYR", "FaFRQ", "ShiXSJ");
                }
                if (dt == null || dt.Rows.Count == 0)
                {
                    return;
                }
                //安排导出在Excel中的列的顺序
                dt.Columns["TiaoMH"].SetOrdinal(0);
                dt.Columns["BaoMC"].SetOrdinal(1);
                dt.Columns["YouXQ"].SetOrdinal(2);
                dt.Columns["BaoZR"].SetOrdinal(3);
                dt.Columns["MieJR"].SetOrdinal(4);
                dt.Columns["MieJRQ"].SetOrdinal(5);
                dt.Columns["MieJGH"].SetOrdinal(6);
                dt.Columns["MieJGC"].SetOrdinal(7);
                if (id == "1" || id == "3")
                {
                    dt.Columns["ShiXSJ"].SetOrdinal(8);
                }
                else
                {
                    dt.Columns["LingYKS"].SetOrdinal(8);
                    dt.Columns["LingYR"].SetOrdinal(9);
                    dt.Columns["ShiYR"].SetOrdinal(10);
                    dt.Columns["FaFRQ"].SetOrdinal(11);
                    dt.Columns["ShiXSJ"].SetOrdinal(12);
                }

                int dtCount = dt.Rows.Count;
                if (dtCount != 0)
                {
                    string strHead = "库存预警包列表";
                    if (id != "1" && id != "3") strHead = "未归还预警包列表";
                    string strFileName = strHead + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls";
                    string headerText = strHead + "一览表";
                    string[] columnNames = new string[] { "条码号", "器械包名称", "有效期", "包装人", "灭菌人", "灭菌日期", "灭菌锅号", "灭菌锅次", "失效日期" };
                    if (id != "1" && id != "3")
                    {
                        columnNames = new string[] { "条码号", "器械包名称", "有效期", "包装人", "灭菌人", "灭菌日期", "灭菌锅号", "灭菌锅次", "领用科室", "领用人", "使用人", "发放日期", "失效日期" };
                    }
                    // 设置编码和附件格式
                    HttpContext.Response.ContentType = "application/vnd.ms-excel";
                    HttpContext.Response.ContentEncoding = Encoding.UTF8;
                    HttpContext.Response.Charset = "";
                    HttpContext.Response.AppendHeader("Content-Disposition",
                    "attachment;filename=" + HttpUtility.UrlEncode(strFileName, Encoding.UTF8));
                    HttpContext.Response.BinaryWrite(NPOIHelper.Export(dt, headerText, columnNames).GetBuffer());
                }
            }
            return;
        }

        //[Description("过期包列表页面")]
        //[ViewPage]
        public ActionResult Index5()
        {
            return View();
        }

        //[Description("预警包列表页面")]
        //[ViewPage]
        public ActionResult Index6()
        {
            return View();
        }

        //加载系统查询
        public ActionResult LoadIndex1(int page, int rows)
        {     
            IEnumerable<V_Package> query = PackageManager.GetAllPackageView().OrderBy(p => p.ZhuangT).ThenBy(p => p.TiaoMH);

            string strLingYKS = Request["LingYKS"];
            string strBaoMC = Request["BaoMC"];
            string strLingYR = Request["LingYR"];
            string strShiYR = Request["ShiYR"];
            string strBegin = Request["BeginDate"];
            string strEnd = Request["EndDate"];

            if (!string.IsNullOrEmpty(strLingYKS))
            {
                query = query.Where(p => { return (!string.IsNullOrEmpty(p.LingYKSBH) && p.LingYKSBH == strLingYKS); });
            }
            if (!string.IsNullOrEmpty(strBaoMC))
            {
                query = query.Where(p => { return (!string.IsNullOrEmpty(p.BaoBH) && p.BaoBH == strBaoMC); });
            }
            if (!string.IsNullOrEmpty(strLingYR))
            {
                query = query.Where(p => { return (!string.IsNullOrEmpty(p.LingYRBH) && p.LingYRBH == strLingYR); });
            }
            if (!string.IsNullOrEmpty(strShiYR))
            {
                query = query.Where(p => { return (!string.IsNullOrEmpty(p.ShiYRBH) && p.ShiYRBH == strShiYR); });
            }
            if (!string.IsNullOrEmpty(strBegin))
            {
                DateTime beginDate = DateTime.Parse(strBegin);
                query = query.Where(p => {

                    return ((!string.IsNullOrEmpty(p.BaoZSJ) && DateTime.Parse(p.BaoZSJ) >= beginDate)
                        || (!string.IsNullOrEmpty(p.MieJSJ) && DateTime.Parse(p.MieJSJ) >= beginDate)
                        || (!string.IsNullOrEmpty(p.FaFSJ) && DateTime.Parse(p.FaFSJ) >= beginDate)
                        || (!string.IsNullOrEmpty(p.HuiSSJ) && DateTime.Parse(p.HuiSSJ) >= beginDate)
                        );
                });
            }
            if (!string.IsNullOrEmpty(strEnd))
            {
                DateTime endDate = DateTime.Parse(strEnd).AddDays(1);
                query = query.Where(p =>
                {
                    return ((!string.IsNullOrEmpty(p.BaoZSJ) && DateTime.Parse(p.BaoZSJ) < endDate)
                        || (!string.IsNullOrEmpty(p.MieJSJ) && DateTime.Parse(p.MieJSJ) < endDate)
                        || (!string.IsNullOrEmpty(p.FaFSJ) && DateTime.Parse(p.FaFSJ) < endDate)
                        || (!string.IsNullOrEmpty(p.HuiSSJ) && DateTime.Parse(p.HuiSSJ) < endDate)
                        );
                });
            }
            var tempList = query.Select(p => new V_Package
            {
                PackageID = p.PackageID,
                TiaoMH = p.TiaoMH,
                BaoBH = p.BaoBH,
                BaoMC = p.BaoMC,
                ZhuangT = p.ZhuangT,
                ZhuangTMC = getZhuangTMC(p.ZhuangT),
                BaoZR = p.BaoZR,
                BaoZRQ = p.BaoZRQ,
                BaoZSJ = p.BaoZSJ,
                QingXQGH = p.QingXQGH,
                QingXQGC = p.QingXQGC,
                MieJR = p.MieJR,
                MieJRQ = p.MieJRQ,
                MieJSJ = p.MieJSJ,
                MieJGC = p.MieJGC,
                MieJGH = p.MieJGH,
                YouXQ = p.YouXQ,
                ShiXSJ = p.ShiXSJ,
                FaFR = p.FaFR,
                FaFRQ = p.FaFRQ,
                FaFSJ = p.FaFSJ,
                LingYKS = p.LingYKS,
                LingYR = p.LingYR,
                ShiYR = p.ShiYR,
                HuiSR = p.HuiSR,
                HuiSRQ = p.HuiSRQ,
                HuiSSJ = p.HuiSSJ
            }).ToList();
            long total = tempList.LongCount();
            exportList1 = tempList.ToList();
            query = query.Skip((page - 1) * rows).Take(rows);
            return this.JsonFormat(new GridData { total = total, rows = query.ToList() });
        }

        //加载操作流程查询
        public ActionResult LoadIndex2(int page, int rows)
        {
            string strCaoZLC = Request["CaoZLC"];
            string strCaoZRQ = Request["CaoZRQ"];
            if (!string.IsNullOrEmpty(strCaoZLC) && PageValidate.IsNumber(strCaoZLC))
            {
                IEnumerable<V_Package> query = PackageManager.GetAllPackageView().Where(p => p.ZhuangT == Convert.ToInt32(strCaoZLC));

                if (!string.IsNullOrEmpty(strCaoZRQ))
                {
                    query = query.Where(p => {
                        string strDate;
                        if (strCaoZLC == "1") strDate = p.BaoZRQ;
                        else if (strCaoZLC == "2") strDate = p.MieJRQ;
                        else if (strCaoZLC == "3") strDate = p.FaFRQ;
                        else strDate = p.HuiSRQ;

                        return strDate == strCaoZRQ;
                    });                   
                }

                if (strCaoZLC == "1") query = query.OrderBy(p => p.BaoZSJ);
                else if (strCaoZLC == "2") query = query.OrderBy(p => p.MieJSJ);
                else if (strCaoZLC == "3") query = query.OrderBy(p => p.FaFSJ);
                else query = query.OrderBy(p => p.HuiSSJ);

                var tempList = query.ToList();
                long total = tempList.LongCount();
                query = query.Skip((page - 1) * rows).Take(rows);
                var list = query.Select(p => new
                {
                    Id = p.PackageID,
                    p.TiaoMH,
                    p.BaoBH,
                    p.BaoMC,
                    p.ZhuangT,
                    ZhuangTMC = getZhuangTMC(p.ZhuangT),
                    p.BaoZR,
                    p.BaoZRQ,
                    BaoZSJ = string.IsNullOrEmpty(p.BaoZSJ) == true ? "" : DateTime.Parse(p.BaoZSJ).ToString("HH:mm:ss"),
                    p.QingXQGH,
                    p.QingXQGC,
                    p.MieJR,
                    p.MieJRQ,
                    MieJSJ = string.IsNullOrEmpty(p.MieJSJ) == true ? "" : DateTime.Parse(p.MieJSJ).ToString("HH:mm:ss"),
                    p.MieJGC,
                    p.MieJGH,
                    p.YouXQ,
                    p.ShiXSJ,
                    p.FaFR,
                    p.FaFRQ,
                    FaFSJ = string.IsNullOrEmpty(p.FaFSJ) == true ? "" : (DateTime.Parse(p.FaFSJ).ToString("HH:mm:ss")),
                    p.LingYKS,
                    p.LingYR,
                    p.ShiYR,
                    p.HuiSR,
                    p.HuiSRQ,
                    HuiSSJ = string.IsNullOrEmpty(p.HuiSSJ) == true ? "" : DateTime.Parse(p.HuiSSJ).ToString("HH:mm:ss")
                });
                return this.JsonFormat(new GridData { total = total, rows = list.ToList() });
            }
            else
            {
                return View();
            }


        }

        //加载条码查询
        public ActionResult LoadIndex3()
        {
            string strTiaoMH = Request["TiaoMH"];

            if (!string.IsNullOrEmpty(strTiaoMH))
            {
                IEnumerable<V_Package> query = PackageManager.GetAllPackageView().Where(p =>
                {
                    string strTempTiaoMH = "," + p.TiaoMH + ",";
                    if (strTiaoMH.Substring(0, 1) != ",") strTiaoMH = "," + strTiaoMH;
                    if (strTiaoMH.Substring(strTiaoMH.Length - 1, 1) != ",") strTiaoMH = strTiaoMH + ",";
                    return strTiaoMH.IndexOf(strTempTiaoMH) != -1;
                });
                return this.JsonFormat(new GridData { total = query.LongCount(), rows = query.ToList() });
            }
            else
            {
                return View();
            }            
        }

        //加载过期预警统计
        public ActionResult LoadIndex4()
        {
            DateTime now = DateTime.Now;
            List<EWView> list = new List<EWView>();

            var KuCList = PackageManager.GetRecordsByPeriodTime("", "", "ZhuangT in (1,2,20,30)");
            var WeiGHList = PackageManager.GetRecordsByPeriodTime("", "", "ZhuangT in (3,40)");

            #region 过期统计

            //过期库存
            long overdueInventoryCount = KuCList.Where(p =>
            {
                return (!string.IsNullOrEmpty(p.ShiXSJ) && now > (DateTime.Parse(p.ShiXSJ).AddDays(1)));
            }).LongCount();
            //过期未归还（病房的）
            long overdueNoReturnCount = WeiGHList.Where(p =>
            {
                return (!string.IsNullOrEmpty(p.ShiXSJ) && now > (DateTime.Parse(p.ShiXSJ).AddDays(1)));
            }).LongCount();

            list.Add(new EWView()
            {
                name = "过期",
                count = overdueInventoryCount,
                ncount = overdueNoReturnCount,
                allcount = overdueInventoryCount + overdueNoReturnCount
            });

            #endregion 

            #region 预警

            //预警库存（有效期7天的，提前1天预警）
            long warningInventory7DaysCount = KuCList.Where(p =>
            {
                if (!string.IsNullOrEmpty(p.ShiXSJ) && p.YouXQ <= 7)
                {
                    DateTime ShiXSJ = DateTime.Parse(p.ShiXSJ);
                    TimeSpan ts = ShiXSJ - now;
                    return (ts.Days == 0);
                }
                else return false;
            }).LongCount();
            //预警未归还（病房的）（有效期7天之内的，提前1天预警）
            long warningNoReturn7DaysCount = WeiGHList.Where(p =>
            {
                if (!string.IsNullOrEmpty(p.ShiXSJ) && p.YouXQ <= 7)
                {
                    DateTime ShiXSJ = DateTime.Parse(p.ShiXSJ);
                    TimeSpan ts = ShiXSJ - now;
                    return (ts.Days == 0);
                }
                else return false;
            }).LongCount();

            list.Add(new EWView()
            {
                name = "有效期7天",
                count = warningInventory7DaysCount,
                ncount = warningNoReturn7DaysCount,
                allcount = warningInventory7DaysCount + warningNoReturn7DaysCount
            });


            //预警库存（有效期大于7天的，提前3天预警）
            long warningInventoryOtherCount = KuCList.Where(p =>
            {
                if (!string.IsNullOrEmpty(p.ShiXSJ) && p.YouXQ > 7)
                {
                    DateTime ShiXSJ = DateTime.Parse(p.ShiXSJ);
                    TimeSpan ts = ShiXSJ - now;
                    return (ts.Days < 3 && ts.Days >= 0);
                }
                else return false;
            }).LongCount();
            //预警未归还（病房的）（有效期大于7天的，提前3天预警）
            long warningNoReturnOtherCount = WeiGHList.Where(p =>
            {
                if (!string.IsNullOrEmpty(p.ShiXSJ) && p.YouXQ > 7)
                {
                    DateTime ShiXSJ = DateTime.Parse(p.ShiXSJ);
                    TimeSpan ts = ShiXSJ - now;
                    return (ts.Days < 3 && ts.Days >= 0);
                }
                else return false; 
            }).LongCount();

            list.Add(new EWView()
            {
                name = "有效期30天及以上",
                count = warningInventoryOtherCount,
                ncount = warningNoReturnOtherCount,
                allcount = warningInventoryOtherCount + warningNoReturnOtherCount
            });

            #endregion

            return this.JsonFormat(new GridData { total = list.LongCount(), rows = list.ToList() });
        }

        //加载过期包
        public ActionResult LoadIndex5(string id)
        {
            DateTime now = DateTime.Now;
            IEnumerable<V_Package> query;
            if (!string.IsNullOrEmpty(id))
            {
                var KuCList = PackageManager.GetRecordsByPeriodTime("", "", "ZhuangT in (1,2,20,30)");
                var WeiGHList = PackageManager.GetRecordsByPeriodTime("", "", "ZhuangT in (3,40)");
                if (id == "1")//库存过期包
                {
                    query = KuCList.Where(p =>
                    {
                        return (!string.IsNullOrEmpty(p.ShiXSJ) && now > (DateTime.Parse(p.ShiXSJ).AddDays(1)));
                    });
                }
                else//未归还（病房）过期包
                {
                    query = WeiGHList.Where(p =>
                    {
                        return (!string.IsNullOrEmpty(p.ShiXSJ) && now > (DateTime.Parse(p.ShiXSJ).AddDays(1)));
                    });
                }
                exportList5 = query.ToList();
                return this.JsonFormat(new GridData { total = query.LongCount(), rows = query.ToList() });
            }
            else
                return View();
        }

        //加载预警包
        public ActionResult LoadIndex6(string id)
        {
            DateTime now = DateTime.Now;
            IEnumerable<V_Package> query;
            if (!string.IsNullOrEmpty(id))
            {
                var KuCList = PackageManager.GetRecordsByPeriodTime("", "", "ZhuangT in (1,2,20,30)");
                var WeiGHList = PackageManager.GetRecordsByPeriodTime("", "", "ZhuangT in (3,40)");
                if (id == "1")//库存有效期7天
                {
                    query = KuCList.Where(p =>
                    {
                        if (p.YouXQ <= 7 && !string.IsNullOrEmpty(p.ShiXSJ))
                        {
                            DateTime ShiXSJ = DateTime.Parse(p.ShiXSJ);
                            TimeSpan ts = ShiXSJ - now;
                            return (ts.Days == 0);
                        }
                        else return false;
                    });
                }
                else if (id == "2")//未归还（病房）有效期7天
                {
                    query = WeiGHList.Where(p =>
                    {
                        if (p.YouXQ <= 7 && !string.IsNullOrEmpty(p.ShiXSJ))
                        {
                            DateTime ShiXSJ = DateTime.Parse(p.ShiXSJ);
                            TimeSpan ts = ShiXSJ - now;
                            return (ts.Days == 0);
                        }
                        else return false;
                    });
                }
                else if (id == "3")//库存有效期30天及以上
                {
                    query = KuCList.Where(p =>
                    {
                        if (p.YouXQ > 7 && !string.IsNullOrEmpty(p.ShiXSJ))
                        {
                            DateTime ShiXSJ = DateTime.Parse(p.ShiXSJ);
                            TimeSpan ts = ShiXSJ - now;
                            return (ts.Days < 3 && ts.Days >= 0);
                        }
                        else return false;
                    });
                }
                else//未归还（病房）有效期30天及以上
                {
                    query = WeiGHList.Where(p =>
                    {
                        if (p.YouXQ > 7 && !string.IsNullOrEmpty(p.ShiXSJ))
                        {
                            DateTime ShiXSJ = DateTime.Parse(p.ShiXSJ);
                            TimeSpan ts = ShiXSJ - now;
                            return (ts.Days < 3 && ts.Days >= 0);
                        }
                        else return false;
                    });
                }
                exportList6 = query.ToList();
                return this.JsonFormat(new GridData { total = query.LongCount(), rows = query.ToList() });
            }
            else
            {
                return View();
            }
        }

        private string getZhuangTMC(int zhuangt)
        {
            if (zhuangt.ToString() == "1") return "包装";
            else if (zhuangt.ToString() == "2") return "灭菌";
            else if (zhuangt.ToString() == "3") return "发放";
            else if (zhuangt.ToString() == "4") return "回收";
            else if (zhuangt.ToString() == "20") return "待灭菌";
            else if (zhuangt.ToString() == "30") return "待发放";
            else if (zhuangt.ToString() == "40") return "待回收";
            else return "其他";
        }
    }
}
